package com.dz.client.service.impl;

import com.dz.client.pojo.UserProduct;
import com.dz.client.mapper.UserProductMapper;
import com.dz.client.service.UserProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dz.server.mapper.ProductMapper;
import com.dz.server.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dz
 * @since 2022-03-26
 */
@Service
public class UserProductServiceImpl extends ServiceImpl<UserProductMapper, UserProduct> implements UserProductService {
    @Autowired
    private UserProductMapper userProductMapper;
    @Autowired
    private ProductMapper productMapper;
    @Override
    public List<Product> getProductIds(Integer uid) {
        List<Integer> productIds = userProductMapper.getProductIds(uid);
        if (productIds==null)
            return null;
        List<Product> products = new ArrayList<>();
        for (Integer productId : productIds) {
            Product product = productMapper.selectById(productId);
            products.add(product);
        }
        return products;
    }
}
